{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5a2e4255",
   "metadata": {},
   "source": [
    "* 2022/9/6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cd28aca0",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_01_ID = \"2100000001\"\n",
    "\n",
    "网新_02_ID = \"2100000002\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "462ce58c",
   "metadata": {},
   "source": [
    "* 判断当前是一周中的星期几，如果是星期二，然后打印Python课表\n",
    "* 实践，通过if判断 实现课程表打印\n",
    "* 课本 p18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "57117af4",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'datemite' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mdatetime\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43mdatemite\u001b[49m\u001b[38;5;241m.\u001b[39mdate\u001b[38;5;241m.\u001b[39mtoday()\n",
      "\u001b[1;31mNameError\u001b[0m: name 'datemite' is not defined"
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "datemite.date.today()\n",
    "# datetime可以获取年月日，但好像不可以周几"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "279a194f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "460a6b4c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "work!\n"
     ]
    }
   ],
   "source": [
    "# 创建today变量(模块获取今天的星期几)\n",
    "# 知识点： 1. 先创建变量\n",
    "\n",
    "today = \"Tuesday\"\n",
    "condition = \"困\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"超开心\") #if条件判断块\n",
    "elif today ==\"Sunday\":\n",
    "    if condition ==\"headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"work!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "504ef95b",
   "metadata": {},
   "source": [
    "* 判断当前是一周中的星期几，如果是星期二，然后打印Python课表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7660c290",
   "metadata": {},
   "outputs": [],
   "source": [
    "# wkday = 0,1,2,3,4,5,6  分别指周一到周日\n",
    "import time\n",
    "\n",
    "wday = time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "321be967",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime().tm_hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "96dfaf30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime().tm_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "dfca2783",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '：' (U+FF1A) (172713547.py, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [15]\u001b[1;36m\u001b[0m\n\u001b[1;33m    else：\u001b[0m\n\u001b[1;37m        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character '：' (U+FF1A)\n"
     ]
    }
   ],
   "source": [
    "if wday != 1: #判断是否为周二\n",
    "    print(\"今天没有python课\")\n",
    "elif time_hour == 12 and time_min >50:\n",
    "    print(\"刚上课 困\")\n",
    "elif time_hour == 13:\n",
    "    print(\"正在上python 还是困\")\n",
    "elif time_hour == 14:\n",
    "    print(\"呜呜还是python 又困又累\")\n",
    "elif time_hour == 15:\n",
    "    print(\"坚持就是胜利！\")\n",
    "elif time_hour == 16 and time_min < 50:\n",
    "    print(\"马上下课！\")\n",
    "else：\n",
    "    print(\"今天下午12：50-16：50是python课，别忘咯\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "94168153",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'time_hour' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m wday \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m: \u001b[38;5;66;03m# 判断是否是周二\u001b[39;00m\n\u001b[0;32m      2\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m今天没有Python课\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[43mtime_hour\u001b[49m \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m12\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m time_min \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m50\u001b[39m:\n\u001b[0;32m      4\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m正在上Python课,刚上课\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m time_hour \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m13\u001b[39m:\n",
      "\u001b[1;31mNameError\u001b[0m: name 'time_hour' is not defined"
     ]
    }
   ],
   "source": [
    "if wday != 1: # 判断是否是周二\n",
    "    print(\"今天没有Python课\")\n",
    "elif time_hour == 12 and time_min > 50:\n",
    "    print(\"正在上Python课,刚上课\")\n",
    "elif time_hour == 13:\n",
    "    print(\"正在上Python课，大概第二节了\")\n",
    "elif time_hour == 14:\n",
    "    print(\"正在上Python课，妈呀，还在上，才2点\")\n",
    "elif time_hour == 15:\n",
    "    print(\"正在上Python课，坚持一下，快下课了！\")\n",
    "elif time_hour == 16 and time_min<50:\n",
    "    print(\"正在上Python课，最后一节课了，块下课啦\")\n",
    "else:\n",
    "    print(\"今天有Python课，上课时间是下午12.50-16.50\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed45848d",
   "metadata": {},
   "source": [
    "## 4.For 循环 内置函数range()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "723cbb35",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "cf50b91b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "337210ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Head First Rocks\n",
      "Head First Rocks\n",
      "Head First Rocks\n",
      "Head First Rocks\n",
      "Head First Rocks\n"
     ]
    }
   ],
   "source": [
    "for num in range(5):\n",
    "    print('Head First Rocks')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "37c86716",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "cannot assign to operator (932455706.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [22]\u001b[1;36m\u001b[0m\n\u001b[1;33m    中大南方-招投标 = \"https://www.nfu.edu.cn/ztb/index.htm\"\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m cannot assign to operator\n"
     ]
    }
   ],
   "source": [
    "# for循环偏离案例 ： 某学校新闻网站数据URL队列获取\n",
    "\n",
    "# 中大南方-招投标- https://www.nfu.edu.cn/ztb/index.htm\n",
    "\n",
    "中大南方-招投标 = \"https://www.nfu.edu.cn/ztb/index.htm\"\n",
    "for page in range(27):\n",
    "    print(\"https://www.nfu.edu.cn/ztb/index\" + str(page) + \".htm\" )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "c18e2feb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/ztb/index0.htm\n",
      "https://www.nfu.edu.cn/ztb/index1.htm\n",
      "https://www.nfu.edu.cn/ztb/index2.htm\n",
      "https://www.nfu.edu.cn/ztb/index3.htm\n",
      "https://www.nfu.edu.cn/ztb/index4.htm\n",
      "https://www.nfu.edu.cn/ztb/index5.htm\n",
      "https://www.nfu.edu.cn/ztb/index6.htm\n",
      "https://www.nfu.edu.cn/ztb/index7.htm\n",
      "https://www.nfu.edu.cn/ztb/index8.htm\n",
      "https://www.nfu.edu.cn/ztb/index9.htm\n",
      "https://www.nfu.edu.cn/ztb/index10.htm\n",
      "https://www.nfu.edu.cn/ztb/index11.htm\n",
      "https://www.nfu.edu.cn/ztb/index12.htm\n",
      "https://www.nfu.edu.cn/ztb/index13.htm\n",
      "https://www.nfu.edu.cn/ztb/index14.htm\n",
      "https://www.nfu.edu.cn/ztb/index15.htm\n",
      "https://www.nfu.edu.cn/ztb/index16.htm\n",
      "https://www.nfu.edu.cn/ztb/index17.htm\n",
      "https://www.nfu.edu.cn/ztb/index18.htm\n",
      "https://www.nfu.edu.cn/ztb/index19.htm\n",
      "https://www.nfu.edu.cn/ztb/index20.htm\n",
      "https://www.nfu.edu.cn/ztb/index21.htm\n",
      "https://www.nfu.edu.cn/ztb/index22.htm\n",
      "https://www.nfu.edu.cn/ztb/index23.htm\n",
      "https://www.nfu.edu.cn/ztb/index24.htm\n",
      "https://www.nfu.edu.cn/ztb/index25.htm\n",
      "https://www.nfu.edu.cn/ztb/index26.htm\n"
     ]
    }
   ],
   "source": [
    "# for循环遍历案例 ： 某学校新闻网站数据URL队列获取\n",
    "\n",
    "# 中大南方-招投标- https://www.nfu.edu.cn/ztb/index.htm\n",
    "\n",
    "中大南方_招投标 = \"https://www.nfu.edu.cn/ztb/index.htm\"\n",
    "for page in range(27):\n",
    "    print(\"https://www.nfu.edu.cn/ztb/index\" + str(page) + \".htm\" )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "edcb530d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "882787dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7698127112519425"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.random方法：取 (0,1)\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "63013887",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.randint(a,b),随机生成a-b之间的一个数值\n",
    "random.randint(1,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "73b4e48e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'jll'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.choice([\"czz\",\"zf\",\"lya\",\"lbl\",\"jll\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "aa929e3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
      "https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n"
     ]
    }
   ],
   "source": [
    "# for循环遍历案例 ： 某学校新闻网站数据URL队列获取\n",
    "\n",
    "# b站-https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\n",
    "\n",
    "b站 = \"https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\"\n",
    "for page in range(27):\n",
    "    print(\"https://www.bilibili.com/anime/?spm_id_from=333.1007.0.0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "195b2f1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "word = \"bottles\"\n",
    "\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,word,\"在啤酒墙上\")\n",
    "    print(beer_num,word,\"啤酒\")\n",
    "     "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
